import { http } from "@/utils/http.js";
import qs from "qs";
const request = {
    // get请求
    get: (url: string, params = {}) => {
        return http({
            url: url,
            method: "GET",
            params,
            headers: { "Content-type": "application/x-www-form-urlencoded" },
        });
    },

    // post请求，json
    post: (url: string, data = {}) => {
        return http({
            url: url,
            method: "POST",
            data,
            headers: { "Content-type": "application/json; charset=utf-8" },
        });
    },
    // post请求，字符串
    postForm: (url: string, data = {}) => {
        return http({
            url: url,
            method: "POST",
            data: qs.stringify(data),
            headers: { "Content-type": "application/x-www-form-urlencoded" },
        });
    },
    // post请求，上传文件
    uploading: (url: string, data = {}) => {
        return http({
            url: url,
            method: "POST",
            data,
            headers: { "Content-type": "multipart/form-data;" },
            // processData: false,
            // contentType: false
        });
    },
    // get请求，下载文件
    download: (url: string, data = {}) => {
        return http({
            url: url,
            method: "GET",
            params: data,
            headers: { "Content-type": "application/x-www-form-urlencoded" },
            responseType: "blob",
        });
    },
};
export default request;
